﻿using System;
using System.Runtime.Serialization;
using System.Security.Permissions;
using System.Text;

namespace Grinder.Fb2
{
    [Serializable]
    public sealed class FictionBookParseException : Exception
    {
        private readonly string _file;

        public string File { get { return _file; } }

        public override string Message
        {
            get
            {
                if (string.IsNullOrEmpty(_file)) return base.Message;
                var msg = new StringBuilder(base.Message);
                msg.Append(_file);
                return msg.ToString();
            }
        }

        public FictionBookParseException() { }
        public FictionBookParseException(string message) : base(message) { }
        public FictionBookParseException(string message, Exception innerException) : base(message, innerException) { }

        public FictionBookParseException(string message, string file) :
            this(message) { _file = file; }

        public FictionBookParseException(string message, string file, Exception innerException) :
            this(message, innerException) { _file = file; }

        private FictionBookParseException(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
            _file = info.GetString("File");
        }

        [SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)]
        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            base.GetObjectData(info, context);
            info.AddValue("File", _file);
        }
    }
}
